/* 
 * 技有限公司版权所有（.cn）.
 * Copyright (c) 2019,  and/or its affiliates. All rights reserved.
 * @Date: 2020.09.01 22:48.
 * @Author 
 * @Description  路由
 **/
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import Layout from '@/layout'

const menus = [{
  path: '/',
  component: Layout, // 项目 二级路由
  hidden: true,
  children: [{
    id: 22,
    path: '/activityList',
    name: 'ActivityList',
    component: () => import( /* webpackChunkName: "about" */ '../views/activityMtg/activityList') // 活动列表
  }, {
    path: '/activityDetail/:id',
    name: 'ActivityDetail',
    // route level code-splitting  this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( /* webpackChunkName: "about" */ '../views/activityMtg/activityDetail') // 活动详情
  }, {
    path: '/activityRenovation/:id',
    name: 'ActivityRenovation',
    component: () => import( /* webpackChunkName: "about" */ '../views/activityMtg/activityRenovation') // 活动装修
  }, {
    path: '/addEdit/:id',
    name: 'AddEdit',
    component: () => import( /* webpackChunkName: "about" */ '../views/activityMtg/addEdit') // 活动 新增 编辑
  }, {
    id: 23,
    path: '/gasList',
    name: 'GasList',
    component: () => import( /* webpackChunkName: "about" */ '../views/gasMtg') // 加油站 列表
  }, {

    path: '/orderDetail/:id',
    name: 'OrderDetail',
    component: () => import( /* webpackChunkName: "about" */ '../views/orderMtg/orderDetail') // 订单 详情
  }, {
    path: '/orderList',
    name: 'OrderList',
    component: () => import( /* webpackChunkName: "about" */ '../views/orderMtg/orderList') // 订单 列表
  }, {
    path: '/systemSet',
    name: 'SystemSet',
    component: () => import( /* webpackChunkName: "about" */ '../views/systemSet') // 账号 管理
  }, {
    path: '/roleMtg',
    name: 'RoleMtg',
    component: () => import( /* webpackChunkName: "about" */ '../views/systemSet/roleMtg') // 角色 管理
  }, {
    path: '/allocMenu/:roleId',
    name: 'AllocMenu',
    component: () => import( /* webpackChunkName: "about" */ '../views/systemSet/allocMenu') // 角色 管理 - 菜单
  }, {
    path: '/allocResource/:roleId',
    name: 'AllocResource',
    component: () => import( /* webpackChunkName: "about" */ '../views/systemSet/allocResource') // 角色 管理 - 资源
  }, {
    path: '/phone',
    name: 'Phone',
    component: () => import( /* webpackChunkName: "about" */ '../views/systemSet/phone') // 手机白名单
  }]
}]

const routes = [{
  path: '/',
  name: 'Login',
  component: () => import( /* webpackChunkName: "about" */ '../views/Login') // 登录
}, ...menus]


const router = new VueRouter({
  // mode: 'history',
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

localStorage.setItem('routerList', JSON.stringify(menus))

router.beforeEach((to, from, next) => {
  if (localStorage.getItem('getRouterToken') == 'error' && to.name != 'Login') {
    next('/')
    return false
  }

  next()

  console.log('router-beforeEach------------', to, from, next, localStorage.getItem('getRouterToken'))
})

export default router